package ch.nostromo.tiffanys.game.chess.pieces;

import java.util.ArrayList;

import ch.nostromo.tiffanys.game.board.Board;
import ch.nostromo.tiffanys.game.board.BoardException;
import ch.nostromo.tiffanys.game.board.BoardTools;
import ch.nostromo.tiffanys.game.move.MoveInput;

public class Knight extends ChessPiece {

  public static ArrayList<MoveInput> getMoveList(Board board, int currentPosition, int owner) throws BoardException {

    ArrayList<MoveInput> result = new ArrayList<MoveInput>();

    int toField = 0;

    toField = currentPosition + 19;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    toField = currentPosition + 21;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    toField = currentPosition + 12;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    toField = currentPosition - 8;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    toField = currentPosition - 19;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    toField = currentPosition - 21;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    toField = currentPosition - 12;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    toField = currentPosition + 8;
    if (board.isValidMoveToField(toField, owner)) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(toField)));
    }

    return result;

  }

}